#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QListView>
#include <QGridLayout>
#include <QSplitter>
#include <QMediaPlayer>
#include <QMenu>
#include <QLabel>
#include <QVideoProbe>
#include <QAudioProbe>
#include "videowidget.h"
#include "playlistmodel.h"
#include "playercontrols.h"
#include "histogramwidget.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void createAction();
    void createMenu();
    void setupModel();
    void setupView();
    void addToPlaylist(const QList<QUrl> urls);
public slots:
    void open();
    void durationChanged(qint64 duration);
    void positionChanged(qint64 progress);
    void metaDataChanged();

    void previousClicked();

    void seek(int seconds);
    void jump(const QModelIndex &index);
    void playlistPositionChanged(int);

    void statusChanged(QMediaPlayer::MediaStatus status);
    void bufferingProgress(int progress);
    void videoAvailableChanged(bool available);

    void displayErrorMessage();

private:
    void clearHistogram();
    void setTrackInfo(const QString &info);
    void setStatusInfo(const QString &info);
    void handleCursor(QMediaPlayer::MediaStatus status);
    void updateDurationInfo(qint64 currentInfo);

    qint64 duration;
    QString trackInfo;
    QString statusInfo;
    QMediaPlayer *player;
    PlayListModel *model;
    QListView *view;

    QWidget *centralWidget;

    QSlider *slider;
    QLabel *labelDuration;
    QHBoxLayout *durationLayout;

    QVBoxLayout *rightLayout;

    VideoWidget *widgetRight;
    QLabel *coverLabel;

    HistogramWidget *videoHistogram;
    HistogramWidget *audioHistogram;
    QVideoProbe *videoProbe;
    QAudioProbe *audioProbe;

    QHBoxLayout *mainLayout;

    QMediaPlaylist *playList;

    QMenu *fileMenu;
    QAction *openFileAction;

};

#endif // MAINWINDOW_H
